<template>
  <div class="login-container">
    <div class="login-form-wrapper">
      <div class="login-header">
        <h2>企业成本管理系统</h2>
        <p>请输入您的账号和密码登录</p>
      </div>
      
      <el-form
        ref="loginFormRef"
        :model="loginForm"
        :rules="loginRules"
        class="login-form"
        @submit.prevent="handleLogin"
      >
    <el-form-item prop="username">
      <el-input 
        v-model="loginForm.username" 
        placeholder="请输入用户名" 
        :prefix-icon="User"
        clearable
        autocomplete="on"
      />
    </el-form-item>
    
    <el-form-item prop="password">
      <el-input 
        v-model="loginForm.password" 
        type="password" 
        placeholder="请输入密码" 
        :prefix-icon="Lock"
        show-password
        clearable
      />
    </el-form-item>
    
    <el-form-item>
      <el-checkbox v-model="loginForm.rememberMe" class="remember-me">记住密码</el-checkbox>
    </el-form-item>
        
        <el-form-item>
          <el-button 
            type="primary" 
            class="login-button" 
            :loading="loading"
            native-type="submit"
          >
            登录
          </el-button>
        </el-form-item>
      </el-form>
      
      <div class="login-footer">
        <p>版本号：v1.0.0</p>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { User, Lock } from '@element-plus/icons-vue'
import { useLogin } from '@/hooks/useLogin'

// 使用登录hook
const { loginForm, loginRules, loading, handleLogin, initForm } = useLogin()

// 表单引用
const loginFormRef = ref(null)

// 生命周期钩子 - 组件挂载时执行
onMounted(() => {
  initForm()
})
</script>

<style scoped>
.login-container {
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-form-wrapper {
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
  padding: 40px;
  width: 100%;
  max-width: 420px;
  transition: transform 0.3s ease;
}

.login-form-wrapper:hover {
  transform: translateY(-5px);
}

.login-header {
  text-align: center;
  margin-bottom: 30px;
}

.login-header h2 {
  color: #303133;
  margin-bottom: 10px;
  font-size: 24px;
}

.login-header p {
  color: #909399;
  font-size: 14px;
}

.login-form {
  width: 100%;
}

.login-form .el-form-item {
  margin-bottom: 24px;
}

.login-form .el-input {
  height: 40px;
}

.login-form .el-input__wrapper {
  border-radius: 8px;
}

.remember-me {
  font-size: 14px;
  color: #606266;
}

.login-button {
  width: 100%;
  height: 40px;
  border-radius: 8px;
  font-size: 16px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  transition: all 0.3s ease;
}

.login-button:hover {
  transform: scale(1.02);
  box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.login-footer {
  text-align: center;
  margin-top: 20px;
}

.login-footer p {
  color: #909399;
  font-size: 12px;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .login-form-wrapper {
    padding: 30px 20px;
  }
  
  .login-header h2 {
    font-size: 20px;
  }
}
</style>